﻿using Sobiens.SPCamlStudio.Entities;
using Sobiens.SPCamlStudio.Services.SharePoint;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml;

namespace Sobiens.SPCamlStudio.UI.Controls
{
    /// <summary>
    /// Interaction logic for CamlTextEditorPane.xaml
    /// </summary>
    public partial class CamlTextEditorPane : UserControl
    {
        public CamlTextEditorPane()
        {
            InitializeComponent();
        }

        public void PopulateCamlTextEditor(CamlFilters filters, List<CamlFieldRef> viewFields, List<CamlOrderBy> orderBys, CamlQueryOptions queryOptions)
        {
            XmlDocument xmlDoc = new XmlDocument();
            XmlNode query = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "");
            query.InnerXml = SPCamlManager.GetCamlString(filters, orderBys);

            XmlNode viewFieldsNode = SPCamlManager.GetViewFieldsXmlNode(viewFields);
            XmlNode queryOptionsNode = SPCamlManager.GetQueryOptionsXmlNode(queryOptions);

            QueryCamlTextBox.Text = query.OuterXml;
            ViewFieldsCamlTextBox.Text = viewFieldsNode.OuterXml;
            QueryOptionsCamlTextBox.Text = queryOptionsNode.OuterXml;
        }
    }
}
